;(function (root, factory) {
    if(typeof exports === "object" && typeof module === "object")
        module.exports = factory();
    else if(typeof define === "function" && define.amd)
        define([], factory);
    else if(typeof exports === "object")
        exports["URandom"] = factory();
    else
        root["URandom"] = factory();
})(this, function () {
    "use strict";

    var URandom = function () {};

    URandom.prototype = {
        constructor: URandom,
        /**
         * 从字库中 随机生成指定长度字符串
         * length 长度
         * resource 字库
         */
        randomString: function (length, resource) {
            length = length || 32;
            var s = "";
            for (var i = 0; i < length; i++) {
                s += resource.charAt(
                    Math.ceil(Math.random() * 1000) % resource.length
                );
            }
            return s;
        },
        // 随机生成8为密码 包含 大写英文字母 小写英文字母 数字 特殊符号其中三种
        randomPassword: function () {
            var source = "abcdefghzklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789-.~!@#$%^&*()_:<>?";
            var letter = "abcdefghzklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ";
            var number = "123456789";
            var mark = "-.~!@#$%&*?<>_:()";
            var range = this.randomString(5, source);
            var lettval = this.randomString(1, letter);
            var numval = this.randomString(1, number);
            var markval = this.randomString(1, mark);
            var pwd = lettval + numval + markval + range;
            return pwd;
        }
    };
    return new URandom();
});